const fp = require('lodash/fp');
const cars = require('./question');


// question-01
let getLastInStock = fp.flowRight(fp.prop('in_stock'), fp.last);
console.log(getLastInStock(cars))


// question-02
let getFirstName = fp.flowRight(fp.prop('name'), fp.first);
console.log(getFirstName(cars))


// question-03
let _average = function(xs) {
  return fp.reduce(fp.add, 0, xs) / xs.length
};
let averageDollarValue = fp.flowRight(_average, fp.map(car => car.dollar_value));
console.log(averageDollarValue(cars))


// question-04
let _underscore = fp.replace(/\W+/g, '_');
let sanitizeName = fp.flowRight(fp.map(_underscore), fp.map(car => car.name));
console.log(sanitizeName(cars))